<?php
require_once dirname(__FILE__) . '/../common/Common.php';
require_once dirname(__FILE__) . '/../dao/dao_live/dao_live.class.php';
require_once dirname(__FILE__) . '/../conf/OutDefine.php';
class GetSign extends AbstractInterface
{
    public function initialize()
    {
        return true;
    }

    public function verifyInput(&$args)//获取参数
    {
        $req = $args['interface']['para'];

        $rules = array(
		//'参数名'=>array('type'=>'参数字段类型');
            'userid' => array('type' => 'string'),
        	//'groupid'=>array('type' => 'string'),
        	//'title' => array('type' => 'string'),
        );
        return $this->_verifyInput($args, $rules);
    }

    public function process()
    {
        interface_log(INFO, EC_OK,"GetSign args=" . var_export($this->_args, true));
        //$config = getConf('ROUTE.DB');

        //$dao_live = new dao_live($config['HOST'], $config['PORT'], $config['USER'], $config['PASSWD'], $config['DBNAME']);
//        $error_message = "";
//    	$ret = $dao_live->AddLiveUser($userid, $live_code,$this->_args['groupid'], $this->_args['title'],$this->_args['userinfo'] , $push_url, $play_url, $hls_play_url,$now_time);
//    	if($ret != 0)
//    	{
//    		$this->_retValue =$ret;
//    		$error_message="db error:no permission";
//    		$this->_retMsg = 'GetSign::process() fail '.genErrMsg($this->_retValue);
//    		return false;
//    	}

        // 确定APP的云API密钥
        $secret_id = CLOUD_API_SECRETID;
        $secret_key = CLOUD_API_SECRETKEY;

        // 确定签名的当前时间和失效时间
        $current = time();
        $expired = $current + 86400;  // 签名有效期：1天

        // 向参数列表填入参数
        $arg_list = array(
            "secretId" => $secret_id,
            "currentTimeStamp" => $current,
            "expireTime" => $expired,
            "random" => rand());
        // 计算签名
        $orignal = http_build_query($arg_list);
        $signature = base64_encode(hash_hmac('SHA1', $orignal, $secret_key, true).$orignal);

        $this->_retValue = EC_OK;//返回数据的状态码
        $this->_data=array("signature" => $signature,"expired" => $expired);//返回数据的数据数组
        interface_log(INFO, EC_OK, 'GetSign::process() succeed');
        return true;
    }
}

?>
